Introduction

3D 4-in-a-Row 5.0

Introduction
3D 4-in-a-Row is a two-player strategy game where the aim is to get a line of four in a row within a 4x4x4 cube. You can play against various challenging computer opponents or a friend at the same computer. New to this version is the ability to write your own computer opponent.

License
3D 4-in-a-Row is shareware and costs $6 to register. Payments can be made by credit card, fax, mail, phone or purchase order thanks to RegSoft. Click here to proceed to the secure order form or here for the non-secure form.

WWW Links
• 3D 4-in-a-Row page - Check for updated versions or more computer opponents.
• cluchey.com - My homepage, with more random software.


Main Interface

This is the main interface of the game.

When it's your turn, click the square you wish to play. Player one is always green and player two is always red.

The current player is indicated by the status box as well as a highlighted graphic.

Note: When a game is finished, double-click the grid to restart or right-click to select players.


New Game Screen

When you choose to create a new game you will be presented with the new game screen. Once you have selected the desired players, click the PLAY button to start the game.

You are presented with a list of players to choose from. These include "Human", namely you or a friend and the rest are computer opponents. To set a player, choose one from the list and click either SET PLAYER 1 or SET PLAYER 2. Your currently selected players are shown at the bottom.

Note: To speed things up a little, double-clicking on a player makes them player 1 and right-clicking makes them player 2.

If you have downloaded more computer opponents, they will only appear in the player list next time the game is run.


Instructions

Concept

The aim of the game is to get a line of four. Unlike ordinary four-in-a-row or Tic Tac Toe games, you play within a 4 x 4 x 4 cube instead of a 4 x 4 grid.

There are consequently 76 possible ways of winning, compared to 10 in a 2D grid. A pretty significant difference, making this game more challenging than it might seem!

So how is the cube represented in the game? You are shown the four layers of the cube. Imagine the cube was sliced and it's layers placed beside each other. It doesn't matter how the cube is sliced, so long as the layers remain in order.

Frequently Asked Questions

Q: So is this basically four simultaneous games of connect-4?
A: No. Although you can quite happily create lines horizontally, vertically and diagonally on each grid, you must remember that this is a cube and not four individual grids. As well as these possibilities, you can also win by playing through the cube. For example, playing the top-left corner of each layer would create a line.

Q: I understand the theory but could use examples of how to win.
A: Refer to this page: Winning Lines.

Q: Can you reach a stalemate?
A: Yes.

Q: Can you create traps?
A: Yes. There can be a great deal of strategy behind playing 3D 4-in-a-Row, not only can traps be created (a situation where your opponent must block one of your two or more lines), but you can force your opponent to play elsewhere while you create your trap. The more challenging computer opponents employ such tactics.


Winning Lines

There are 76 possible lines in a 4x4x4 cube. Select lines from the drop-down boxes below to have them displayed.


Usage

Computer opponents are stored in .DLL files which must be kept in the same directory as 3d4r50.exe.

3D 4-in-a-Row 5.0 comes with four computer opponents of varying difficulty. Check this website to see if new or updated opponents are available for download.

New in this version of 3D 4-in-a-Row is the ability to write your own computer opponents. More information on that available here.


Writing Computer Opponents

Computer opponent AI algorithms are stored in dynamic link libraries. These are loaded by the game and polled when it's their turn to play.

The supplied opponents have all been written using Delphi, but you are free to use another language, provided it can compile to a compatible DLL.

Click here for the annotated Delphi source for Monkeybot.


Monkeybot Source Listing

This is the source code for Monkeybot which you are free to use as a template for writing your own computer opponents. It has been written in Delphi 6 and should be compatible with most other versions. These files are available online for download here.

Monkeybot.dpr

library Monkeybot;

{$R Monkeybot.res}

uses
  Classes;

type
  TCellValue = 0..2;
  TCell = record
    Value: TCellValue;
    PlayIdx: Integer;
  end;
  TCells = array[1..4,1..4,1..4] of TCell;
  {The cube is a TCells object. TCells is a three-dimensional array (4x4x4) of
  TCell. Each cell has a value of 0 (empty), 1 (move by P1) or 2 (move by P2).}
  TCoord = record
    x,y,z: 1..4;
  end;

function Coord(x,y,z: Integer): TCoord;
begin
  Result.x := x;
  Result.y := y;
  Result.z := z;
end;

function GetInfo(Info: Integer): PChar; export;
begin
  {Returns information about your player}
  case Info of
    0: Result := 'Monkeybot'; {Name}
    1: Result := 'Monkeybot doesn''t know how to play the game.'; {Description}
    2: Result := '1.0'; {Version}
    3: Result := 'Yann Cluchey'; {Author}
    4: Result := 'http://www.cluchey.com/'; {Homepage}
  else Result := '';
  end;
end;

procedure OnNewGame(Opponents: PChar; Cube: TCells; PlayerNum: TCellValue);
                   export;
begin
  {This gets called every time a new game is started. The DLL is kept in memory
  between games, giving you the possibility to adjust your tactics depending on
  previous games.
  • Opponents: PChar; - Your opponent's name (Legacy).
  • Cube: TCells; - The contents of the cube. Empty, unless the user loads a
    saved game.
  • PlayerNum: TCellValue; - Your player number. Either 1 or 2.}
end;

procedure OnMove(APos: TCoord; Value: TCellValue; Cube: TCells;
                 PlayerNum: TCellValue); export;
begin
  {(Legacy) Called every time a move is made. (Including by you).
  • APos: TCoord; - Last played coordinate.
  • Value: TCells; - The value (= player number), either 1 or 2.
  • Cube: TCells; - The contents of the cube.
  • PlayerNum: TCellValue; - Your player number.}
end;

function Move(Cube: TCells; PlayerNum: TCellValue): TCoord; export;
var
  x,y,z: Integer;
  List: array of TCoord;
begin
  {Called when it's your turn to move.
  • Cube: TCells; - The contents of the cube.
  • PlayerNum: TCellValue; - Your player number.
  Returns a TCoord - the coordinate you would like to play.}

  {Monkeybot is a stupid opponent. It determines which cells are free and
  chooses one at random.}

  SetLength(List,0);
  for x := 1 to 4 do
  begin
    for y := 1 to 4 do
    begin
      for z := 1 to 4 do
      begin
        if Cube[x,y,z].Value = 0 then
        begin
          SetLength(List,High(List)+2);
          List[High(List)].x := x;
          List[High(List)].y := y;
          List[High(List)].z := z;
        end;
      end;
    end;
  end;

  Randomize;
  x := Random(High(List)+1);
  Result := Coord(List[x].x,List[x].y,List[x].z);

end;

exports
  GetInfo,
  OnNewGame,
  OnMove,
  Move;

begin
end.

Tip: To make development more convenient, set the output directory to that of 3D 4-in-a-Row and the host application to 3d4r50.exe.

Monkeybot.rc

1 Bitmap Monkeybot1.bmp
2 Bitmap Monkeybot2.bmp

These bitmaps are the player glyphs displayed in the game. Bitmap 1 is the player 1 glyph and bitmap 2 is the player 2 glyph. To build Monkeybot.res use Borland's Resource Compiler from the command line. Type this: "BRCC32 Monkeybot"

Final Words

If you create a computer opponent, submit it and it will be made available for download on the website. If you have any questions, feel free to contact me.